package resource;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;


public class DB{
	private String host = "jdbc:mysql://localhost:3306/fricker";
	private String usuario = "root";
	private String senha = "040805";
	private Connection conexao;
	private static DB instance;
	
	public static DB getInstance(){
		if(instance==null)
			instance = new DB();
		return instance;
	}
	
	private DB(){
		carregarDriverMysql();
		setConexao();
	}
	
	private boolean carregarDriverMysql(){
		try{
			Class.forName("com.mysql.jdbc.Driver");
		}
		catch(ClassNotFoundException excessao){
			System.out.println("Exception: "+excessao.getMessage()+" on "+excessao.getClass());
			return false;
		}
		return true;
	}
	
	private boolean setConexao(){
		try{
			this.conexao = DriverManager.getConnection(this.host,this.usuario,this.senha);
		}
		catch(SQLException excessao){
			System.out.println("Exception: "+excessao.getMessage()+" on "+excessao.getClass());
			return false;
		}
		return true;
	}
	
	public Connection conecta(){
		return this.conexao;
	}
}